﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ColumnMapping.cs" company="CodePlex">
//   Copyright © CodePlex 2012
// </copyright>
// <summary>
//   Defines the ColumnMapping type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DataFramework.Attributes
{
    using System;
    using System.Data;

    /// <summary>
    /// Attribute that maps a object property to a field in the database.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class ColumnMapping : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnMapping"/> class.
        /// </summary>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="type">Type of the column in the DB.</param>
        /// <param name="isKey">if set to <c>true</c>, this column [is a key] field.</param>
        public ColumnMapping(string columnName, DbType type, bool isKey) :
            this(columnName, type, isKey, false)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnMapping"/> class.
        /// </summary>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="type">Type of the column in the DB.</param>
        /// <param name="isKey">if set to <c>true</c>, this column [is a key] field.</param>
        /// <param name="isAutoId">if set to <c>true</c> [is auto id].</param>
        public ColumnMapping(string columnName, DbType type, bool isKey, bool isAutoId)
        {
            this.ColumnName = columnName;
            this.DbType = type;
            this.IsKey = isKey;
            this.IsAutoId = isAutoId;
        }

        /// <summary>
        /// Gets the name of the column.
        /// </summary>
        /// <value>The name of the column.</value>
        public string ColumnName { get; private set; }

        /// <summary>
        /// Gets the type of the db.
        /// </summary>
        /// <value>The type of the db.</value>
        public DbType DbType { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is key.
        /// </summary>
        /// <value><c>true</c> if this instance is key; otherwise, <c>false</c>.</value>
        public bool IsKey { get; private set; }

        /// <summary>
        /// Gets or sets a value indicating whether this column has it's key field assigned at the database level.
        /// </summary>
        /// <value>
        ///     <c>true</c> if this instance is auto id; otherwise, <c>false</c>.
        /// </value>
        public bool IsAutoId { get; set; }
    }
}
